package cn.com.dcsgo.controller;

import cn.com.dcsgo.domain.Area;
import cn.com.dcsgo.model.Result;
import cn.com.dcsgo.service.AreaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 地址管理相关接口
 *
 * @author Dcsgo
 * @since 2025/10/27 10:39
 */
@Tag(name = "地址管理相关接口")
@RestController
@RequestMapping("admin/area")
public class AreaController {
    @Resource
    private AreaService areaService;

    @GetMapping("list")
    @PreAuthorize("hasAuthority('admin:area:list')")
    @Operation(summary = "获取所有地址信息", description = "需要自行转换成层级结构")
    public Result<List<Area>> getAreaList() {
        return Result.success(areaService.list());
    }

    @GetMapping("listByPid")
    @Operation(summary = "获取地址列表",description = "根据父节点ID获取")
    public Result<List<Area>> getAreaListByPid(@RequestParam("pid") Long pid){
        return Result.success(areaService.listByPid(pid));
    }
    //TODO: 增、删、改（批量导入）
}
